use serde::Deserialize;

/// minio连接配置
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct MinioConfig {

    /// 如果指定了url
    /// 则忽略 host、port、ssl的值
    url: Option<String>,
    /// 是否加密
    #[serde(default)]
    ssl: bool,
    /// ip
    host: Option<String>,
    /// 端口
    port: Option<u16>,
    /// 区域
    region: Option<String>,
    /// 用户名
    access_key: Option<String>,
    /// 密码
    secret_key: Option<String>,
    /// bucket
    bucket: Option<String>
}

impl Default for MinioConfig {
    fn default() -> Self {
        Self{
            url: None,
            ssl: false,
            host: None,
            port: None,
            region: None,
            access_key: None,
            secret_key: None,
            bucket:None
        }
    }
}

impl MinioConfig {
    pub fn url(&self) -> Option<&String> {
        self.url.as_ref()
    }

    pub fn ssl(&self) -> bool {
        self.ssl
    }

    pub fn host(&self) -> &str {
        self.host.as_deref().unwrap_or("127.0.0.1")
    }

    pub fn port(&self) -> u16 {
        self.port.unwrap_or(9000)
    }

    pub fn region(&self) -> &str {
        self.region.as_deref().unwrap_or("")
    }

    pub fn access_key(&self) -> &str {
        self.access_key.as_deref().unwrap_or("minioadmin")
    }

    pub fn secret_key(&self) -> &str {
        self.secret_key.as_deref().unwrap_or("minioadmin")
    }

    pub fn bucket(&self) -> &str {
        self.bucket.as_deref().unwrap_or("test")
    }

}